package me.zhengjie.modules.account.factory.entity;


import java.math.BigDecimal;

/**
 * @description: 云南利息算法工具类，所有计息公式都调用此类，如果改到算法就只用修改此类
 * @author: Administrator
 * @create: 2022-01-05 14:24
 **/
public class AccountCalculatInter {
    /**
     * @param capital           本金
     * @param interestRate      利率
     * @param numberOfmonthsDue  应缴月数
     * @param aae001            年度
     * @param aae042            计息截止年月
     * @param deadlineYear      截止年度
     * @return {@link BigDecimal }
     * @Description 计算历年利息
     * @Author jzy
     * @Date 2022/04/18
     */
    public static BigDecimal calculatPastYearInter(BigDecimal capital,BigDecimal interestRate,BigDecimal numberOfmonthsDue,Integer aae001,Integer aae042,Integer deadlineYear){
        //历年利息（2006前:本金*利率*应缴月数/12;
        // 2006后:本金*利率;
        // 最后截止年月，是本金*利率*所占月数/12）
        BigDecimal returnInter=BigDecimal.ZERO;
        if (aae001 <= 2006) {
            if (aae001.intValue()>deadlineYear.intValue()){
                return returnInter;
            }else {
                returnInter = capital.multiply(interestRate).multiply(numberOfmonthsDue).divide(BigDecimal.valueOf(12),4,BigDecimal.ROUND_HALF_UP).setScale(2, BigDecimal.ROUND_HALF_UP);
                if (aae001.intValue() == deadlineYear.intValue()) {
                    Integer ys = aae042 % 100;
                    BigDecimal bigDecimalYs=new BigDecimal(ys);
                    returnInter = returnInter.multiply(bigDecimalYs).divide(BigDecimal.valueOf(12),4,BigDecimal.ROUND_HALF_UP).setScale(2, BigDecimal.ROUND_HALF_UP);
                }
            }

            return returnInter;
        }else{
            if (aae001.intValue()>deadlineYear.intValue()){
                return returnInter;
            }else {
                if (aae001.intValue() == deadlineYear.intValue()) {
                    Integer ys = aae042 % 100;
                    BigDecimal bigDecimalYs = new BigDecimal(ys);
                    returnInter = capital.multiply(interestRate).multiply(bigDecimalYs).divide(BigDecimal.valueOf(12), 6, BigDecimal.ROUND_HALF_UP).setScale(2, BigDecimal.ROUND_HALF_UP);
                } else {
                    returnInter = capital.multiply(interestRate).setScale(2, BigDecimal.ROUND_HALF_UP);
                }
            }
            return returnInter;
        }

    }

    /**
     * 计算当年利息
      * @param capital 本金
     * @param interestRate 利率
     * @param actualMonths 应缴月数
     * @param aae001 年度
     * @param deadlineYear 截止年度
     * @return
     */
    public static BigDecimal calculatThisYearInter(BigDecimal capital,BigDecimal interestRate,Integer actualMonths,Integer aae001,Integer deadlineYear){
        //当年利息（2006前:本金*利率*实缴/12/2;
        // 2006后:本金*利率*1.083/2）
        BigDecimal returnInter=BigDecimal.ZERO;
        if (aae001.intValue()>deadlineYear.intValue()) {
            return returnInter;
        }else {
            if (aae001 <= 2006) {
                returnInter = capital.multiply(interestRate).multiply(BigDecimal.valueOf(actualMonths)).divide(BigDecimal.valueOf(12), 6, BigDecimal.ROUND_HALF_UP).divide(BigDecimal.valueOf(2), 6, BigDecimal.ROUND_HALF_UP).setScale(2, BigDecimal.ROUND_HALF_UP);
            } else {
                returnInter = capital.multiply(interestRate).multiply(BigDecimal.valueOf(1.083)).divide(BigDecimal.valueOf(2)).setScale(2, BigDecimal.ROUND_HALF_UP);
            }
        }
        return returnInter;

    }


}



